<?php

namespace app\admin\controller;

use app\admin\logic\BranchLogic;
use think\Request;

class Branch extends Base
{
    private $branchLogin;

    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        $this->branchLogin = new BranchLogic();
    }

    // 列表页
    public function index()
    {
        $branchs = $this->branchLogin->findAll();
        $this->assign('list', $branchs);
        return $this->fetch();
    }

    // 新增和修改页面
    public function add($id = "")
    {
        $branch = null;
        if (!empty($id)) {
            $branch = $this->branchLogin->findById($id);
        }
        $this->assign("branch", $branch);
        return $this->fetch();
    }

    public function doAdd($param = '')
    {
        $data = json_decode($param, true);
        $res = $this->branchLogin->andAndUpdate($data);
        return $res;
    }

    // 删除方法
    public function del($id)
    {
        return (new BranchLogic())->del($id);
    }
}